package io.renren.modules.heartself.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.heartself.dao.HeartMusicDao;
import io.renren.modules.heartself.entity.HeartMusicEntity;
import io.renren.modules.heartself.service.HeartMusicService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("heartMusicService")
public class HeartMusicServiceImpl extends ServiceImpl<HeartMusicDao, HeartMusicEntity> implements HeartMusicService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String directory = (String) params.get("directory");
        Long userId = Long.parseLong(params.get("userId").toString());
        IPage<HeartMusicEntity> page = this.page(
                new Query<HeartMusicEntity>().getPage(params),
                new QueryWrapper<HeartMusicEntity>().like(StringUtils.isNotBlank(directory), "directory", directory)
                        .eq(userId != null, "user_id", userId)
        );

        return new PageUtils(page);
    }

}